// Replication code for "Deposit Insurance Premiums and Bank Risk," by Edward Kim and Marcelo Rezende, forthcoming in the Review of Corporate Finance Studies.


clear all
set mem 640m
set maxiter 20
set more off

use "RCFS Kim Rezende Data Example 1"

global instruct "stats(coef se) bdec(3) tdec(3) rdec(4) alpha(.01, .05)"

// This command drops new banks and bank with total assets below $100 million. 
keep if newinst == 0 & tot_assets < 10000000

tsset id_rssd newdate

gen fcd = F.chgdep_assess_base_ratio_an_bp

// The items in the next paragraph can be obtained from Call Reports.  For the sake of brevity, we simply set their value to zero here.

gen RCFDG466 = 0
gen RCFDG467 = 0
gen RCFDG468 = 0
gen RCFDG470 = 0
gen RCFDG471 = 0
gen RCFDG472 = 0
gen RCFDK655 = 0
gen RCFD8274 = 0
gen RCON2365 = 0


replace RCFDG466 = 0 if RCFDG466 == .
replace RCFDG467 = 0 if RCFDG467 == .
replace RCFDG468 = 0 if RCFDG468 == .
replace RCFDG470 = 0 if RCFDG470 == .
replace RCFDG471 = 0 if RCFDG471 == .
replace RCFDG472 = 0 if RCFDG472 == .
replace RCFDK655 = 0 if RCFDK655 == .
replace RCFD8274 = 0 if RCFD8274 == .

gen uda = (40 + base_ar) * (RCFDG466 + RCFDG467 + RCFDG468 + RCFDG470 + RCFDG471 + RCFDG472) / (tot_avg_assets_k - ab_avgtaneq - bkbded - ctdded)
gen dida = 50 * (RCFDK655 - (RCFD8274 * 0.03)) / (tot_avg_assets_k - ab_avgtaneq - bkbded - ctdded)
replace dida = 0 if dida < 0
gen bdr = RCON2365  / (tot_avg_assets_k - ab_avgtaneq - bkbded - ctdded)


tsset id_rssd newdate



gen lffs = ln(fedfunds_sold )
gen lsr = ln(sec_resell  )
gen lex = ln(ex_reserves2)
gen lffp = ln(fedfunds_purch)
gen lres = ln(reserves)
gen lavgres = ln(avg_reserves )
gen lavgexres = ln(avg_ex_reserves )
gen forw_lex = F.lex
gen forw_lavgexres = F.lavgexres
gen forw_lres = F.lres
gen forw_lffs = F.lffs
gen forw_lffp = F.lffp
gen lag_roa = L.roa
gen lag_roe = L.roe

gen lffsandrepo = ln(fedfunds_sold + rcfdb989)
gen forw_lffsandrepo = F.lffsandrepo 
gen lffpandrepo = ln(fedfunds_purch + rcfdb995)
gen forw_lffpandrepo = F.lffpandrepo 


tsset id_rssd newdate
gen forw_base_ar = F.base_ar

// ********** RKD Assumptions
// Density tests around the 5 cutoff
rddensity base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0 & tot_assets > 100000 & tot_assets < 10000000 , c(5)
rddensity base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0 & tot_assets > 100000 & tot_assets < 10000000 , c(5) bwselect(diff)
rddensity base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0 & tot_assets > 100000 & tot_assets < 10000000 , c(5) fitselect(restricted)

// Table 1: Summary statistics
sum reserves ex_reserves2 avg_reserves avg_ex_reserves fedfunds_sold rconb993 base_ar calc_tier1 calc_loanspastdue calc_nonpf calc_netchgoff calc_netinc wcamels tot_cap_ratio tier1_ratio roa roe if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 

// Table 2: Effects of assessment rates on bank reserves
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lavgexres base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & forw_lex != ., c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) 
rdrobust forw_lavgexres base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & forw_lex != ., c(5)  deriv(1) vce(cluster id_rssd) 

// Table 3: Effects of assessment rates on interbank lending
rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lffp base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) 
rdrobust forw_lffp base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) 

rdrobust forw_lffsandrepo base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & forw_lffs != ., c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lffpandrepo base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & forw_lffp != ., c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lffsandrepo base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & forw_lffs != ., c(5)  deriv(1) vce(cluster id_rssd) 
rdrobust forw_lffpandrepo base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & forw_lffp != ., c(5)  deriv(1) vce(cluster id_rssd) 

// Table 4: Effects of assessment rates with alternative bandwidths
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2) bwselect(cerrd)
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2) bwselect(mserd)
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2) bwselect(certwo)
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2) bwselect(msetwo)

rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2) bwselect(cerrd)
rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2) bwselect(mserd)
rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2) bwselect(certwo)
rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2) bwselect(msetwo)

// Table C.2: Treatment effects on covariates
rdrobust calc_tier1 base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust calc_loanspastdue base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust calc_nonpf base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust calc_netchgoff base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust calc_netinc base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust wcamels base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust tot_cap_ratio base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust tier1_ratio base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust lag_roa base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust lag_roe base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)

// Table C.3: Effects of assessment rates using alternative cutoffs 
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(2)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(3)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(4)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(6)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(7)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(8)  deriv(1) vce(cluster id_rssd) p(1) q(2)

rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(2)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(3)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(4)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(6)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(7)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(8)  deriv(1) vce(cluster id_rssd) p(1) q(2)

// Table C.4: Effects of assessment rates excluding observations near the cutoff
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & abs(base_ar - 5) > 0.005, c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & abs(base_ar - 5) > 0.010, c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & abs(base_ar - 5) > 0.015, c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & abs(base_ar - 5) > 0.020, c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)

rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & abs(base_ar - 5) > 0.005, c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & abs(base_ar - 5) > 0.010, c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & abs(base_ar - 5) > 0.015, c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)
rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & abs(base_ar - 5) > 0.020, c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2)

rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2) bwselect(cerrd)
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & abs(base_ar - 5) > 0.005, c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2) bwselect(cerrd)
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & abs(base_ar - 5) > 0.010, c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2) bwselect(cerrd)
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & abs(base_ar - 5) > 0.015, c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2) bwselect(cerrd)
rdrobust forw_lex base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & abs(base_ar - 5) > 0.020, c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2) bwselect(cerrd)

rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000, c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2) bwselect(cerrd)
rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & abs(base_ar - 5) > 0.005, c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2) bwselect(cerrd)
rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & abs(base_ar - 5) > 0.010, c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2) bwselect(cerrd)
rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & abs(base_ar - 5) > 0.015, c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2) bwselect(cerrd)
rdrobust forw_lffs base_ar if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000  & abs(base_ar - 5) > 0.020, c(5)  deriv(1) vce(cluster id_rssd) p(1) q(2) bwselect(cerrd)

// Table D.1: Correlation of assessment rates over time
tab date_sas, gen (dt)
// Note: in the original dataset, there are 108 different dates.  The original code was adjusted to the shorter and fake dataset provided for replication.

xtreg forw_base_ar base_ar dt1 if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 , fe cluster(id_rssd)
xtreg forw_base_ar base_ar dt1 if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 & base_ar > 3 & base_ar < 7, fe cluster(id_rssd)
xtreg forw_base_ar base_ar dt1 if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 & base_ar > 4 & base_ar < 6, fe cluster(id_rssd)
xtreg forw_base_ar base_ar dt1 if riskcat == 1   & newinst == 0 & uda == 0 & dida == 0 & bdr == 0  & tot_assets > 100000 & tot_assets < 5000000 & base_ar > 4.5 & base_ar < 5.5, fe cluster(id_rssd)
